﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using xunsearch.lib;
using System.Configuration;

namespace xunsearch.web
{
    public class EXunSearch
    {
        public XS _xs;
        private XSTokenizerScws _scws;
        public string project = "demo";
        public string charset = "utf-8";
        public void init() 
        {
            string xsRoot = "./app/";
            project = ConfigurationManager.AppSettings["project"];
            charset = ConfigurationManager.AppSettings["charset"];
            xsRoot += project + ".ini";
            
            xsRoot = HttpContext.Current.Server.MapPath(xsRoot);
            _xs = new XS(xsRoot);
            _xs.setDefaultCharset(charset);
        }

        public void add(Dictionary<string, string> data) 
        {
            update(data, true);
        }
        public void update(XSDocument data, bool add = false) 
        {
            _xs.getIndex().update(data, add);
        }
        public void update(Dictionary<string, string> data, bool add = false)
        {
            XSDocument doc = new XSDocument(data);
            update(doc);
        }

        public XSTokenizerScws getScws() 
        {
            if (_scws == null) 
            {
                _scws = new XSTokenizerScws();
            }
            return _scws;
        }
    }
}